package com.bjsxt.controller;

import com.bjsxt.pojo.Admin;
import com.bjsxt.pojo.PageA;
import com.bjsxt.service.AdminService;
import org.omg.PortableInterceptor.INACTIVE;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class Admincontroller  {
    @Autowired
    private  AdminService adminService;
    //添加管理员
    @RequestMapping("/insertAdmin")
    public Integer insertAdmin(Admin admin,Integer rid){
        return adminService.insertAdmin(admin,rid);
    }
    //用户退出操作
    @RequestMapping("/adminLoginOut")
    public String adminLoginOut(HttpSession session){
        //手动注销session
        session.invalidate();
        //跳转到登陆页面
        return  "redirect:/login.jsp";
    }

    //用户登陆实现
    @ResponseBody
    @RequestMapping("/adminlogin")
    public boolean findOne(String  aname, String apwd, HttpSession session){
        Admin admin = adminService.findOne(aname, apwd);
        if (admin!=null){
            session.setAttribute("admin",admin);
            return true;
        }
        return false;
    }

    //查询所有管理员的实现
    @RequestMapping("/findAll")
    @ResponseBody
    public PageA<Admin> findAll(Integer page,Integer rows){
        return adminService.selectAll(page, rows);

    }

}
